<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('新增补货单')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <input type="hidden" class="layui-input" th:value="${id}" id="inputID" name="id">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                    <a class="layui-btn" style="float: right" id="addSave">保存</a>
                </section>
            </div>
        </div>
    </div>
</div>
</body>


<div th:include="public/public_js::public_js"></div>
<style type="text/css">

</style>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        });
        $("#load").on("click",function(){
            //console.log(123);
            var data = {
                ids:[],
                page:0,
                rows:10
            };
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:9191/zxsswms/WmsDeliveryDetailsController/ShippingdetailsExcel", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            xhr.send(JSON.stringify({
                "ids": [],
                "page":0,
                "rows":10
            }));
        })
    });
    layui.use(['list','layer','zzpUtils','jquery','laydate'],function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        window.operateEvent = {
            "click #edit": function (e, value, row, index) { //行按钮编辑
                editRow(row);
            },
        }
        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        })
        laydate.render({
            elem: '#test6'
            , theme: '#20a0ff'
        })
        var id = $('#inputID').val();
        console.log('intpuid', id);
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            showColumns: false,
            pagination: true,
            url: '/wmsshipmentorder/getShipmentOrder',
            columns: [
                {
                field: '',
                checkbox: true },
                {
                    field: 'cjsj',
                    title: '创建时间'
                }, {
                    field: 'fybh',
                    title: 'SO编号'
                },{
                    field: 'khmc',
                    title: '客户名称'
                },{
                    field: 'lxrxm',
                    title: '联系人'
                },{
                    field: 'lxrdh',
                    title: '电话'
                },{
                    field: 'khdz',
                    title: '地址'
                },{
                    field: 'show_lx',
                    title: '单据类型'
                },{
                    field: 'pxs',
                    title: '品项数'
                },{
                    field: 'zsl',
                    title: '总数量'
                },{
                    field: 'jhfhsj',
                    title: '计划发货时间'
                }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }

        });
//
        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })
        $('#addSave').click(function () {
            var ids = [];
            //使用getSelections即可获得行数据，row是json格式的数据
            var getSelectRows = $("#table").bootstrapTable('getSelections', function (row) {
                return row;
            });
            getSelectRows.forEach(item => {
                console.log(item);
                ids.push(item.id);
            });
//            console.log('ids',ids);
            $.ajax({
                url: "/zxsswms/wmsorderrepair/add",
                type: "POST",
                dataType: "JSON",
                contentType: 'application/json',
                async: false,
                data:JSON.stringify({ids}),
                success: function (data) {
                    console.log(666666, data);
//                    $table.bootstrapTable('append', $('#bhsl').val());
                    if (data.type !== 'warning') {
                        layer.msg(data.title);
//                        location.reload();
                    } else {
                        layer.msg(data.message);
                    }
                },
                error: function () { console.log("Error"); }
            });
        })
    });
</script>
</html>